﻿using System.ComponentModel;
using System.Drawing.Design;
using TA.Turbo.Design;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Client script include from a file in the application directory.
	/// </summary>
	public class ScriptFileInclude : BaseFileInclude, IScriptInclude
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public ScriptFileInclude()
		{
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Gets or sets the virtual path of the file to be included.
		/// </summary>
		[Editor(typeof(ScriptUrlEditor), typeof(UITypeEditor))]
		public override string Src
		{
			get
			{
				return base.Src;
			}
			set
			{
				base.Src = value;
			}
		}
		public override IncludeType IncludeType
		{
			get { return IncludeType.Script; }
		}
		#endregion
		#region METHODS
		public override string GetClientUrl()
		{
			if (TPage.Current.OptimizeScripts && this.Optimize)
			{
				string content = this.Content;
				content = TPage.Current.Obfuscator.Obfuscate(content, TPage.Current.OptimizeScripts);

				CombinedContent cc = CombinedContent.Get(content, "text/javascript");
				return string.Format("~/TurboResource.axd?k={0}&filename={1}", cc.Key, this.FileName);

			}
			else
			{
				return TPage.DoResolveUrl(this.Src);
			}
		}
		#endregion
		#endregion
	}
}